package com.ruoyi.web.controller.faq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.faq.domain.FaqKnowledge;
import com.ruoyi.faq.service.IFaqKnowledgeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * FAQ知识库Controller
 *
 * @author ruoyi
 * @date 2025-06-13
 */
@RestController
@RequestMapping("/faq/knowledge")
public class FaqKnowledgeController extends BaseController
{
    @Autowired
    private IFaqKnowledgeService faqKnowledgeService;

    /**
     * 查询FAQ知识库列表
     */
    @PreAuthorize("@ss.hasPermi('faq:knowledge:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaqKnowledge faqKnowledge)
    {
        startPage();
        List<FaqKnowledge> list = faqKnowledgeService.selectFaqKnowledgeList(faqKnowledge);
        return getDataTable(list);
    }

    /**
     * 导出FAQ知识库列表
     */
    @PreAuthorize("@ss.hasPermi('faq:knowledge:export')")
    @Log(title = "FAQ知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaqKnowledge faqKnowledge)
    {
        List<FaqKnowledge> list = faqKnowledgeService.selectFaqKnowledgeList(faqKnowledge);
        ExcelUtil<FaqKnowledge> util = new ExcelUtil<FaqKnowledge>(FaqKnowledge.class);
        util.exportExcel(response, list, "FAQ知识库数据");
    }

    /**
     * 获取FAQ知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('faq:knowledge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faqKnowledgeService.selectFaqKnowledgeById(id));
    }

    /**
     * 新增FAQ知识库
     */
    @PreAuthorize("@ss.hasPermi('faq:knowledge:add')")
    @Log(title = "FAQ知识库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaqKnowledge faqKnowledge)
    {
        return toAjax(faqKnowledgeService.insertFaqKnowledge(faqKnowledge));
    }

    /**
     * 修改FAQ知识库
     */
    @PreAuthorize("@ss.hasPermi('faq:knowledge:edit')")
    @Log(title = "FAQ知识库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaqKnowledge faqKnowledge)
    {
        return toAjax(faqKnowledgeService.updateFaqKnowledge(faqKnowledge));
    }

    /**
     * 删除FAQ知识库
     */
    @PreAuthorize("@ss.hasPermi('faq:knowledge:remove')")
    @Log(title = "FAQ知识库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faqKnowledgeService.deleteFaqKnowledgeByIds(ids));
    }
}
